<!DOCTYPE html>
<html lang="en">
<head>
    
    <meta charset="utf-8">
    <title>is/is.js - Documentation</title>
    
    
    <script src="scripts/prettify/prettify.js"></script>
    <script src="scripts/prettify/lang-css.js"></script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
    <script src="scripts/nav.js" defer></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>

<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
  <div class="navicon"></div>
</label>

<label for="nav-trigger" class="overlay"></label>

<nav >
    
    <h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="color.html">color</a><ul class='methods'><li data-type='method'><a href="color.html#.setColorOpacity">setColorOpacity</a></li></ul></li><li><a href="data.html">data</a><ul class='methods'><li data-type='method'><a href="data.html#.getMax">getMax</a></li><li data-type='method'><a href="data.html#.getMin">getMin</a></li><li data-type='method'><a href="data.html#.getTotal">getTotal</a></li><li data-type='method'><a href="data.html#.toArray">toArray</a></li><li data-type='method'><a href="data.html#.toJson">toJson</a></li></ul></li><li><a href="date.html">date</a><ul class='methods'><li data-type='method'><a href="date.html#.dateFormat">dateFormat</a></li><li data-type='method'><a href="date.html#.getDate">getDate</a></li></ul></li><li><a href="is.html">is</a><ul class='methods'><li data-type='method'><a href="is.html#.isIDCard">isIDCard</a></li><li data-type='method'><a href="is.html#.isPhone">isPhone</a></li><li data-type='method'><a href="is.html#.isType">isType</a></li></ul></li></ul>
</nav>

<div id="main">
    
    <h1 class="page-title">is/is.js</h1>
    

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>/**
 * 判断数据类型：输入数据和数据类型，判断是否一致
 * 
 * @memberof is
 * 
 * @param {Any} value 数据（必传）
 * 
 * @param {String} type 类型（必传）
 * &lt;br /> 可选：Array，Object，Number,String,Boolean,Undefined,Null,Function
 * 
 * @returns true or false
 * 
 * @example  
 * isType(1,'Number'); // true
 */
function isType(value, type) {
    if (Object.prototype.toString.call(value).indexOf(type) !== -1) {
        return true
    } else {
        return false
    }
}
/**
 * 判断号码是否为手机号
 * 
 * @memberof is
 * 
 * @param {String} number 手机号（必传）
 * 
 * @returns true or false
 * 
 * @example  
 * isPhone('1111111111'); // false
 * isPhone('18453076019'); // true
 */
function isPhone(number) {
    if (!number) return false
    if (/^1[3|4|5|7|8]\d{9}$/.test(number)) {
        return true;
    } else {
        return false;
    }

}
/**
 * 判断号码是否为身份证号，参考https://www.jb51.net/article/136639.htm
 * 
 * @memberof is
 * 
 * @param {String} number 身份证号（必传）
 * 
 * @returns true or false
 * 
 * @example  
 * isIDCard('111111111111111111'); // false
 * isIDCard('372922199905032335'); // true
 */
function isIDCard(number) {
    // 格式和校验码计算
    const checkCode = function (val) {
     const p = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
     const factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
     const parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
     let code = val.substring(17);
     if(p.test(val)) {
      let sum = 0;
      for(let i=0;i&lt;17;i++) {
       sum += val[i]*factor[i];
      }
      if(parity[sum % 11] == code.toUpperCase()) {
       return true;
      }
     }
     return false;
    }
    // 检验省份代码
    const checkProv = function (val) {
     const pattern = /^[1-9][0-9]/;
     const provs = {11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门"};
     if(pattern.test(val) &amp;&amp; provs[val]) {
        return true;
     }
     return false;
    }
    // 校验出生日期
    const checkDate = function (val) {
     const pattern = /^(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)$/;
     if(pattern.test(val)) {
         return true;
     }else{
         return false;
     }
    }
    
    // 身份证号校验
     if(checkCode(number)&amp;&amp;checkProv(number.substring(0,2))&amp;&amp;checkDate(number.substring(6,14))) {
         return true
     }
     return false;
}
module.exports.isType = isType
module.exports.isPhone = isPhone
module.exports.isIDCard = isIDCard
</code></pre>
        </article>
    </section>




    
    
</div>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.6</a> on Wed Feb 24 2021 16:40:34 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>



</body>
</html>
